//
//  NLoginModel.m
//
//  Created by mac  on 2018/12/5
//  Copyright (c) 2018 __MyCompanyName__. All rights reserved.
//

#import "NLoginModel.h"


NSString *const kNLoginModelToken = @"Token";
NSString *const kNLoginModelGoodCommentIDs = @"GoodCommentIDs";
NSString *const kNLoginModelTopicalOfFollowed = @"TopicalOfFollowed";
NSString *const kNLoginModelNickName = @"NickName";
NSString *const kNLoginModelGoodArticleIDs = @"GoodArticleIDs";
NSString *const kNLoginModelHeadPic = @"HeadPic";
NSString *const kNLoginModelUserCode = @"UserCode";
NSString *const kNLoginModelID = @"ID";


@interface NLoginModel ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation NLoginModel

@synthesize token = _token;
@synthesize goodCommentIDs = _goodCommentIDs;
@synthesize topicalOfFollowed = _topicalOfFollowed;
@synthesize nickName = _nickName;
@synthesize goodArticleIDs = _goodArticleIDs;
@synthesize headPic = _headPic;
@synthesize userCode = _userCode;
@synthesize iDProperty = _iDProperty;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict
{
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if(self && [dict isKindOfClass:[NSDictionary class]]) {
        self.token = [self objectOrNilForKey:kNLoginModelToken fromDictionary:dict];
        self.goodCommentIDs = [self objectOrNilForKey:kNLoginModelGoodCommentIDs fromDictionary:dict];
        self.topicalOfFollowed = [self objectOrNilForKey:kNLoginModelTopicalOfFollowed fromDictionary:dict];
        self.nickName = [self objectOrNilForKey:kNLoginModelNickName fromDictionary:dict];
        self.goodArticleIDs = [self objectOrNilForKey:kNLoginModelGoodArticleIDs fromDictionary:dict];
        self.headPic = [self objectOrNilForKey:kNLoginModelHeadPic fromDictionary:dict];
        self.userCode = [self objectOrNilForKey:kNLoginModelUserCode fromDictionary:dict];
        self.iDProperty = [self objectOrNilForKey:kNLoginModelID fromDictionary:dict];
        
    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:self.token forKey:kNLoginModelToken];
    [mutableDict setValue:self.goodCommentIDs forKey:kNLoginModelGoodCommentIDs];
    [mutableDict setValue:self.topicalOfFollowed forKey:kNLoginModelTopicalOfFollowed];
    [mutableDict setValue:self.nickName forKey:kNLoginModelNickName];
    [mutableDict setValue:self.goodArticleIDs forKey:kNLoginModelGoodArticleIDs];
    [mutableDict setValue:self.headPic forKey:kNLoginModelHeadPic];
    [mutableDict setValue:self.userCode forKey:kNLoginModelUserCode];
    [mutableDict setValue:self.iDProperty forKey:kNLoginModelID];
    
    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description
{
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super init];
    
    self.token = [aDecoder decodeObjectForKey:kNLoginModelToken];
    self.goodCommentIDs = [aDecoder decodeObjectForKey:kNLoginModelGoodCommentIDs];
    self.topicalOfFollowed = [aDecoder decodeObjectForKey:kNLoginModelTopicalOfFollowed];
    self.nickName = [aDecoder decodeObjectForKey:kNLoginModelNickName];
    self.goodArticleIDs = [aDecoder decodeObjectForKey:kNLoginModelGoodArticleIDs];
    self.headPic = [aDecoder decodeObjectForKey:kNLoginModelHeadPic];
    self.userCode = [aDecoder decodeObjectForKey:kNLoginModelUserCode];
    self.iDProperty = [aDecoder decodeObjectForKey:kNLoginModelID];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{
    
    [aCoder encodeObject:_token forKey:kNLoginModelToken];
    [aCoder encodeObject:_goodCommentIDs forKey:kNLoginModelGoodCommentIDs];
    [aCoder encodeObject:_topicalOfFollowed forKey:kNLoginModelTopicalOfFollowed];
    [aCoder encodeObject:_nickName forKey:kNLoginModelNickName];
    [aCoder encodeObject:_goodArticleIDs forKey:kNLoginModelGoodArticleIDs];
    [aCoder encodeObject:_headPic forKey:kNLoginModelHeadPic];
    [aCoder encodeObject:_userCode forKey:kNLoginModelUserCode];
    [aCoder encodeObject:_iDProperty forKey:kNLoginModelID];
}

- (id)copyWithZone:(NSZone *)zone
{
    NLoginModel *copy = [[NLoginModel alloc] init];
    
    if (copy) {
        
        copy.token = [self.token copyWithZone:zone];
        copy.goodCommentIDs = [self.goodCommentIDs copyWithZone:zone];
        copy.topicalOfFollowed = [self.topicalOfFollowed copyWithZone:zone];
        copy.nickName = [self.nickName copyWithZone:zone];
        copy.goodArticleIDs = [self.goodArticleIDs copyWithZone:zone];
        copy.headPic = [self.headPic copyWithZone:zone];
        copy.userCode = [self.userCode copyWithZone:zone];
        copy.iDProperty = [self.iDProperty copyWithZone:zone];
    }
    
    return copy;
}



@end
